<template>
    <div>
        <h2 align="center">病人用药信息-修改</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">药品名称</td>
                    <td><input type="text" v-model="quertInfo1.medicalName" ></td>
                </tr>
                <tr>
                    <td align="right">科室</td>
                    <td>
                        <select v-model="quertInfo1.departId">
                            <option value="">请选择</option>
                            <option v-for="item in data1" :key="item.id" :value="item.id">{{item.department}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">用药日期</td>
                    <td><input type="date" v-model="quertInfo1.medicatime" ></td>
                </tr>
                <tr>
                    <td align="right">病人姓名</td>
                    <td><input type="text"  v-model="quertInfo1.patientName"></td>
                </tr>
                <tr>
                    <td align="right">病房号码</td>
                    <td><input type="text" v-model="quertInfo1.patientNumber" ></td>
                </tr>
                <tr>
                    <td align="right">用药状态</td>
                    <td>
                        <input type="radio" name="state" :value="1" v-model="quertInfo1.state">未开始
                        <input type="radio" name="state" :value="0" v-model="quertInfo1.state">已完成
                    </td>
                </tr>
                
                <tr>
                    <td align="right">配药医生</td>
                    <td><input type="text"  v-model="quertInfo1.dispensingdoctors"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok" class="btn btn-primary"></td>
                </tr>   
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref, reactive,onMounted} from 'vue'
import {useRouter, useRoute} from 'vue-router'
import axios from 'axios';
import moment from 'moment';
let router = useRouter()
let route = useRoute()
//用药管理
let quertInfo1 = reactive({
  medicalName: "",
  departId: "",
  medicatime: "",
  patientName: "",
  patientNumber: "",
  state: 1,
  dispensingdoctors: "",
  id: route.query.id,
})
 const ok = () => {
     if(quertInfo1.medicalName == ''){
        alert('输入用药名称');
        return;
     }
     
     if(quertInfo1.medicatime == ''){
         alert('选择用药时间');
         return;
     }
     if(quertInfo1.patientName == ''){
         alert('输入病人姓名');
         return;
     }
     if(quertInfo1.patientNumber == ''){
         alert('输入病房号码');
         return;
     }
     if(quertInfo1.dispensingdoctors == ''){
         alert('输入发药医生');
         return;
     }
     axios({
        url: '/api/Medication/MedicaUpt',
        method: 'put',
        data: quertInfo1
     })
     .then((res)=>{
         if(res.data==1){
            alert('修改成功');
            router.push('/MedicationList')
         }
         else if(res.data==-1){
            alert('药品名称已存在');
         }
         else{
            alert('修改失败');
         }
     })

 }




//科室管理
let data1:any= ref([])
onMounted(()=>{
    GetDepartmentList();
    GetFantian();
})
const GetFantian = () => {
    axios({
        url: '/api/Medication/GetMedicationId',
        method: 'get',
        params: {
            id: route.query.id
        }
    })
    .then((res) => {
        console.log(res);
        quertInfo1.medicalName=res.data.medicalName;
        quertInfo1.departId=res.data.departId;
        quertInfo1.medicatime=moment(res.data.medicatime).format('YYYY-MM-DD');
        quertInfo1.patientName=res.data.patientName;
        quertInfo1.patientNumber=res.data.patientNumber;
        quertInfo1.state=res.data.state;
        quertInfo1.dispensingdoctors=res.data.dispensingdoctors;
    })
}
let quertInfo= reactive({
    departmen: '',
})
const GetDepartmentList = () => {
    axios({
        url: '/api/Department/GetDepartmentList',
        method: 'get',
        params: quertInfo
    })
    .then((res) => {
        console.log(res);
        data1.value = res.data;
    })
}

</script>

<style scoped>

</style>